import request from '@/utils/request'
import ImageCompressor from 'image-compressor.js' // 引入图片压缩

export function getParam(key) {
  return request({
    url: '/msg/' + key,
    method: 'get'
  })
}

export function zip(file) {
  return new Promise((resolve, reject) => {
    let imageCompressor = new ImageCompressor() // 压缩成功则使用压缩的结果，不成功直接上传
    imageCompressor.compress(file, {
      quality: 0.6, maxHeight: 1000, maxWidth: 1000
    }).then((result) => { // 压缩成功的回调
      let blob = new Blob([result], {type: file.type})
      resolve(new window.File([blob], file.name, {type: file.type}))  // 压缩成功把压缩成功的数据传递给ajax.js
    }).catch((err) => { // 压缩失败的回调
      console.log(err)
      reject(file)      // 压缩失败把原文件传递
    })
  });
}





